<?php

namespace Biz\model\GoodsTestActivity;

use Medoo\Medoo;

class FineGoodsContentModel extends \Doraemon\pockets\datebase\BaseDbModel
{
    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'fine_goods_test_activity_content';

    public const IS_DELETE_TRUE = 9;
    public const IS_DELETE_FALSE = 2;

    /**
     * 获取一行
     * @param $where
     * @param string $field
     * @return array|mixed|null
     */
    public static function first($where, $field = '*')
    {
        $rs = self::get($field, $where);
        if (!$rs) {
            return null;
        }
        return $rs;
    }

    /**
     * 批量查询
     * @param $where
     * @param  $field
     * @return array
     */
    public static function all($where, $field = '*')
    {
        return self::select($field, $where);
    }

    public static function hasReport($basiciIds)
    {
        $result = [];
        $list = self::select(['id', 'basic_id'], ['basic_id' => $basiciIds, 'is_delete[!]' => self::IS_DELETE_TRUE]);
        foreach ($list as $row) {
            $result[$row['basic_id']] = 1;
        }
        foreach ($basiciIds as $basicId) {
            if (!isset($result[$basicId])) {
                $result[$basicId] = 0;
            }
        }
        return $result;
    }

    /**
     * 获取一列的值
     * @param $where
     * @param array $field
     * @return array|bool
     */
    public static function pluck($where, array $field = ['id'])
    {
        return self::select($field, $where);
    }

    /**
     * 从记录中获取单个值
     * @param $where
     * @param string $columns
     * @return array|bool
     */
    public static function value($where, string $columns = 'id')
    {
        return self::get($columns, $where);
    }

    /**
     * @param $map
     * @return array|bool
     */
    public static function getCountMaps($map)
    {
        return self::select(['cnt' => Medoo::raw('count(uid)'), 'uid'], $map);
    }
}